package br.com.infocruz.seam.crm.ejb.facade;

import javax.ejb.Stateless;
import javax.persistence.EntityNotFoundException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;

import org.apache.log4j.Logger;
import org.jboss.seam.annotations.Name;

import br.com.infocruz.seam.crm.ejb.model.UserAccount;

@Name("userAccountFacade")
@Stateless
public class UserAccountFacadeBean extends AbstractFacade<UserAccount> implements UserAccountFacade {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static Logger log = Logger.getLogger(UserAccountFacadeBean.class);

	public UserAccountFacadeBean() {
		super(UserAccount.class);
	}

	@Override
	public UserAccount findByUsername(String username) {
		UserAccount userAccount = null;
		if (username != null) {
			Query query = createNamedQuery("UserAccount.findByUsername");
			query.setParameter("username", username);
			try {
				userAccount = (UserAccount) query.getSingleResult();
			} catch (EntityNotFoundException e) {
				log.warn(e.getMessage());
			} catch (NonUniqueResultException e) {
				log.warn(e.getMessage());
			}
		}
		return userAccount;
	}

}
